package com.sicheng.蓝桥.练习题;

import com.sicheng.datastruct.tree.HeroNode;
import org.junit.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author zsc
 * @version 1.0
 * @date 2021/11/8 11:30
 */
@SuppressWarnings("all")
public class 蓝桥 {
    @Test
    public void test3() {
        Integer[] nums = {1, 2, 3, 4};
        Arrays.sort(nums, 0, 3, Comparator.reverseOrder());
        System.out.println(Arrays.toString(nums));
        System.out.println((1 << 7) - 1);
    }

    public static void main(String[] args) {

//        System.out.println(pingTo());
        showTime(9808900);

    }

    public static void showTime(long timeStamp) {
        Date date = new Date(timeStamp);
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        //System.out.println(dateFormat.format(date));
        String format = dateFormat.format(date);
        String[] strings = format.split(":");
        int hh;
        if (strings[0].startsWith("0"))
            hh = Integer.parseInt(strings[0].substring(1));
        else
            hh = Integer.parseInt(strings[0]);

        hh -= 8;
        System.out.printf("%02d:%s:%s", hh, strings[1], strings[2]);

    }

    public static int numberOfTwo(int num) {


        int sum = 0;
        for (int i = 1; i <= num; i++) {
            String value = String.valueOf(i);
            for (int j = 0; j < value.length(); j++) {
                if (value.charAt(j) == '2') {
                    sum++;
                }
            }
        }

        return sum;
    }

    //最大共约数
    public static int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public static int 既约分数(int num) {
        int count = 0;
        for (int i = 1; i <= num; i++) {
            for (int j = 1; j <= num; j++) {
                if (gcd(i, j) == 1)
                    count++;
            }
        }
        return count;
    }


    /**
     * 小蓝有很多数字卡片，每张卡片上都是数字 0 到 9。
     * 小蓝准备用这些卡片来拼一些数，
     * 他想从 1 开始拼出正整数，每拼一个，就保存起来，卡片就不能用来拼其它数了。
     * 小蓝想知道自己能从 1 拼到多少。
     * <p>
     * 例如，当小蓝有 30 张卡片，其中 0 到 9 各 3 张，
     * 则小蓝可以拼出 1 到 10， 但是拼 11 时卡片 1 已经只有一张了，不够拼出 11。
     * <p>
     * 现在小蓝手里有 0 到 9 的卡片各 2021 张，共 20210 张，请问小蓝可以从 1 拼到多少？
     */
    public static int pingTo() {
        HashMap<Integer, Integer> cards = new HashMap<>();

        cards.put(0, 2021);
        cards.put(1, 2021);
        cards.put(2, 2021);
        cards.put(3, 2021);
        cards.put(4, 2021);
        cards.put(5, 2021);
        cards.put(6, 2021);
        cards.put(7, 2021);
        cards.put(8, 2021);
        cards.put(9, 2021);

        int total = 0;
        boolean flag = true;
        for (int i = 1; i <= 20210; i++) {
            String nums = String.valueOf(i);
            for (int j = 0; j < nums.length(); j++) {
                int num = nums.charAt(j) - '0';
                Integer count = cards.get(num);
                if (count == 0) {
                    return total;
                }
                cards.put(num, count - 1);
            }

            total++;
        }

        return total;

    }


    @Test
    public void 杨辉三角() {
        long s = System.currentTimeMillis();
        int n = 20000;
        System.out.println(n * (n + 1) / 2 + 2);
        int[][] ints = new int[30000][30000];
        int length = ints.length;
        for (int k = 0; k < n; k++) {
            ints[k][0] = 1;
        }
        int count = 2;
        for (int i = 1; i < length; i++) {
            for (int j = 1; j <= i; j++) {
                count++;
                ints[i][j] = ints[i - 1][j] + ints[i - 1][j - 1];
                if (ints[i][j] == n) {
                    long end = System.currentTimeMillis();
                    System.out.println((end - s) * 1.0 / 1000 + "s");
                    System.out.println(count);
                    return;
                }
            }
            count++;
        }
    }

    @Test
    public void 双向排列() {

        try {
            Scanner scanner = new Scanner(new File("src/com/atguigu/file/双向排列.txt"));

            int n = scanner.nextInt();
            int m = scanner.nextInt();

            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = i + 1;
            }
            while (scanner.hasNext()) {
                int p = scanner.nextInt();//操作，0表示从a[0]-a[p-1]降序，1表示从a[p-1]到a[n-1]升序
                int q = scanner.nextInt();//
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test() {
        long start1 = System.nanoTime();
        long i = 1_0;//000_000;
        System.out.println(i % 2 == 0);
        long end1 = System.nanoTime();

        System.out.println((end1 - start1) + "ns");

        long start2 = System.nanoTime();
        System.out.println(i >> 2 << 2 == i);
        long end2 = System.nanoTime();
        System.out.println((end2 - start2) + "ns");


        System.out.println("##########");
        long start3 = System.nanoTime();
        System.out.println(Tools.mod(i, 2L));
        long end3 = System.nanoTime();
        System.out.println((end3 - start3) + "ns");
    }

    @Test
    public void test1() {
        HeroNode node1 = new HeroNode(1, "1");
        HeroNode node2 = new HeroNode(1, "1");
        HeroNode node3 = new HeroNode(1, "1");
        node1.left = node2;
        node1.right = node3;

        node2 = change(node2);

        System.out.println(node1.left);
    }

    public HeroNode change(HeroNode node) {
        return new HeroNode(2, "2");
    }

}
